﻿@using Pear.Web.Core
@inherits PearRazorPage<object>
@{ Layout = "~/Views/Shared/_UserBox.cshtml"; }
@{ ViewData["Title"] = "登录页";}
@section header
{
    <link rel="stylesheet" href="/admin/css/other/login.css" />
}
<div class="layui-form-item">
    <img class="logo" src="/admin/images/logo.png" />
    <div class="title">Pear Admin</div>
    <div class="desc">
        Pear Admin Furion MVC 案例
    </div>
</div>
<div class="layui-form-item">
    <input type="text" value="admin" placeholder="账 户 : admin " name="account" lay-verify="account" hover class="layui-input" />
</div>
<div class="layui-form-item">
    <input type="text" value="admin" placeholder="密 码 : admin " name="password" lay-verify="password" hover class="layui-input" />
</div>
<div class="layui-form-item">
    <input type="text" placeholder="计算图片中的结果" name="captcha" lay-verify="captcha" hover class="code layui-input layui-input-inline" />
    <a href="javascript:void(0);" title="点击更换验证码">
        <img src="@Url.Action("CaptchaImage","User")" class="codeImage" />
    </a> 
</div>
<div class="layui-form-item">
    <button type="button" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
        登 入
    </button>
</div>

@section footer
{
    <script>
        layui.use(['form', 'jquery', 'button', 'popup', 'http'], function () {
            var form = layui.form;
            var button = layui.button;
            var popup = layui.popup;
            var $ = layui.jquery;
            var http = layui.http;



            form.verify({
                account: function (value, item) {
                    if (value.length < 5) return '请输入至少5位账户';
                },
                password: function (value) {
                    if (value.length < 5) return '请输入至少5位密码';
                },
                captcha: function (value) {
                    if (value.length < 1) return '请输入验证码';
                }
            });

            $(".codeImage").click(function () {
                $(this).attr("src", '@Url.Action("CaptchaImage","User")' + '?t=' + new Date().getTime());
            });

            form.on('submit(login)', function (data) {
                var btn = button.load({ elem: '.login' })
                http.post("@Url.Action("Login","User")", JSON.stringify(data.field)).then((result) => {
                    if (result.succeeded) {
                            btn.stop(function () {
                                popup.success("登录成功", function () {
                                    location.href = "@Url.Action("Index","Home", new { area = "Admin" })";
                                });
                            })
                        } else {
                            btn.stop(function () {
                                popup.failure(result.errors.message);
                            })
                        }
                });
                return false;
            });
        })
    </script>


}